package service.impl;

import entity.AdminDO;
import entity.StudentDO;
import entity.StudentLoginDO;
import service.AdminService;
import service.StudentLoginService;
import service.StudentService;
import util.DBUtil;
import util.RedisUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class StudentLoginServiceImpI implements StudentLoginService {
    String user;

    @Override
    public boolean validateStudent(StudentLoginDO studentLoginDO) {

        String username = studentLoginDO.getUsername();
        String pwdParm = studentLoginDO.getPwd();
        RedisUtil redisUtil = new RedisUtil();
        String returnpwd = redisUtil.getPassWord(username);
        System.out.println(returnpwd);
        if (pwdParm.equals( returnpwd)){
            return true;
        }else {
            return false;
        }


//        String username = studentLoginDO.getUsername();
//        studentLoginDO.setUsername(studentLoginDO.getUsername());
//        String pwdParm = studentLoginDO.getPwd();
//        String sql = "select pwd from stuclient where username = ?";
//        Connection conn = null;
//        PreparedStatement ps = null;
//        //ResultSet rs = null;
//        ResultSet resultSet = null;
//        try {
//            conn = DBUtil.getConn();
//            if (conn == null) {
//                return false;
//            }
//            ps = conn.prepareStatement(sql);
//            ps.setString(1, studentLoginDO.getUsername());
//            resultSet = ps.executeQuery();
//            while (resultSet.next()) {
//                String pwd = resultSet.getString(1);
//                if (studentLoginDO.getPwd().equals(pwd)) {
//                    return true;
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            DBUtil.closeRs(resultSet);
//            DBUtil.closePs(ps);
//            DBUtil.closeConn(conn);
//        }
//        return false;
    }

    //0626
    public String getUser11() {
        return user;
    }
}
